package 创建线程;

public class 实现Runnable {

    public static void main(String[] args) {
        //实现Runnable写法1
        Thread t1 = new Thread(new MyRunnable());
        t1.start();

        //实现Runnable写法2：匿名内部类
        Runnable r2 = new Runnable() {//属于Runnable接口的实现类（没有名字）
            @Override
            public void run() {
                System.out.println("匿名内部类run");
            }
        };
        Thread t2 = new Thread(r2);
        t2.start();

        //实现Runnable写法3：也可以把匿名内部类对象，直接写在构造方法的参数上
        Thread t3 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("匿名内部类run");
            }
        });
        t3.start();

        //了解：lambda表达式
        Thread t4 = new Thread(() -> System.out.println("匿名内部类run"));
        t4.start();
    }

    private static class MyRunnable implements Runnable{
        @Override
        public void run() {
            System.out.println("MyRunnable run");
        }
    }
}
